package soft;

import java.util.Random;

public class Lab_01 {
    public static void main(String[] args) {
        // 创建随机数生成器
        Random random = new Random();

        System.out.println("=== 50道100以内加减法口算题 ===");
        System.out.println("题目\t\t\t答案");
        System.out.println("================================");

        // 生成50道题目
        for (int i = 1; i <= 50; i++) {
            // 随机生成两个0-100的数字
            int num1 = random.nextInt(101);  // 0-100
            int num2 = random.nextInt(101);  // 0-100

            // 随机决定是加法还是减法
            boolean isAddition = random.nextBoolean();

            int result;
            String operator;
            String question;

            if (isAddition) {
                // 加法题目
                operator = "+";
                result = num1 + num2;
                question = String.format("%2d. %2d + %2d = ", i, num1, num2);
            } else {
                // 减法题目：确保结果不为负数
                if (num1 < num2) {
                    // 交换位置确保非负结果
                    int temp = num1;
                    num1 = num2;
                    num2 = temp;
                }
                operator = "-";
                result = num1 - num2;
                question = String.format("%2d. %2d - %2d = ", i, num1, num2);
            }

            // 输出题目和答案
            System.out.println(question + "\t\t" + result);
        }
    }
}
